import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-15
 * Time: 17:52
 */
public class test_1 {
    public static final Object lock = new Object();
    public static volatile int count = 0;
    public static volatile int sum = 0;

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() {
                synchronized (this) {
                    count++;
                }
                return count;
            }
        };

        for (int i = 0; i < 1000; i++) {
            FutureTask<Integer> futureTask = new FutureTask<>(callable);
            Thread t = new Thread(futureTask);
            t.start();
            synchronized (lock) {
                int res = futureTask.get();
                sum += res;
            }
        }
        System.out.println(sum);
    }
}
